<template lang="pug">
  el-button(:type="type" @click="exportFile") {{ text }}
</template>

<script>
import { download } from "@/utils/tools";
export default {
    props: {
        text: {
            type: String,
            required: true
        },
        action: {
            type: String,
            default: ""
        },
        api: {
            type: String,
            default: ""
        },
        type: {
            type: String,
            default: ""
        },
        payload: {
            type: Object,
            default: () => ({})
        }
    },
    methods: {
        exportFile() {
            if (this.action) {
                this.$store.dispatch(`${this.action}`, this.payload).then(data => {
                    location.href = data.download;
                });
            } else if (this.api) {
                download(this.api, this.payload);
            }
        }
    }
};
</script>
